package main


import (
    "fmt"
    "strconv"
    "io/ioutil"
    "os"
    "bufio"
)


func convertToBin(num int) string {
    result := ""
    for ; num > 0; num /= 2 {
        lsb := num % 2
        result += strconv.Itoa(lsb)
    }
    return result
}


func readFile() {
    const filename = "123.txt"
    if contents, err := ioutil.ReadFile(filename); err != nil {
        fmt.Println(err)
    }else {
        fmt.Printf("%s ", contents )
    }
}


func printFile(filename string) {
    file, err := os.Open(filename)
    if err != nil {
        panic(err)
    }
    scanner := bufio.NewScanner(file)
    
    // for scanner.Scan() {
    //     fmt.Println("##################")
    //     fmt.Println(scanner.Text())
    // }

    for scanner.Scan() {
        if num, err := strconv.Atoi(scanner.Text()); err == nil {
            fmt.Printf("%s ", convertToBin(num))
        }
    }
    fmt.Println()

    for scanner.Scan() {
        num, _ := strconv.Atoi(scanner.Text())
        fmt.Printf("%s ", convertToBin(num))
    }
    fmt.Println()
}


func main(){
    fmt.Printf("%s %s %s \n",
        convertToBin(2),
        convertToBin(5),
        convertToBin(11),
    )
    // readFile()
    printFile("123.txt")
}

